package org.bpms.service.admin;

import java.util.UUID;

import org.bpms.model.admin.Bookversion;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;

/**
 * 版本管理
 * @author hupei
 *
 */
public class BookversionService {
	/**
	 * 保存
	 * @param version
	 */
	@Before(Tx.class)
	public void save(Bookversion version){
		if (null == version.get("id")){
			version.set("id", UUID.randomUUID().toString().replaceAll("-", ""));
		}
		version.save();
	}
	
	/**
	 * 查找最后一个版本号
	 * @return
	 */
	public Bookversion findLast(String bookid){
		String sql = "select * from bookversion where bookid=? order by version desc";
		return Bookversion.me.findFirst(sql , bookid);
	}
}
